package com.exposit.zbs.entity;
// Generated 29.07.2014 20:51:37 by Hibernate Tools 3.6.0


import org.dozer.Mapping;
import org.hibernate.annotations.*;
import org.hibernate.annotations.NamedQueries;
import org.hibernate.annotations.NamedQuery;

import javax.persistence.CascadeType;
import javax.persistence.*;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import static javax.persistence.GenerationType.IDENTITY;


/**
 * GrantApplicationEntity generated by hbm2java
 */
@NamedQueries({@NamedQuery(
		name = "getGrantByStatus",
		query = "from GrantApplicationEntity ga where ga.grantApplicationStatus.grantStatusName=:status"), @NamedQuery(
		name = "getCountOfRequestedGrantApplications",
		query = "select count(*) from GrantApplicationEntity ga where ga.grantApplicationStatus.grantStatusName='REQUESTED'"), @NamedQuery(
		name = "getGrantsByGrantArea",
		query = "from GrantApplicationEntity as ga where ga.grantApplicationStatus.grantStatusName='ACCEPTED' AND ga.grantArea.grantAreaId=:grantAreaId order by ga.likes.size desc ")})
@Entity
@Table(name = "grantApplication", catalog = "investfond")
public class GrantApplicationEntity implements java.io.Serializable, Comparable<GrantApplicationEntity> {

	@Mapping("grantId")
	private Long grantId;
	@Mapping("grantArea")
	private GrantAreaEntity grantArea;
	private GrantApplicationStatusEntity grantApplicationStatus;
	private UserEntity user;
	private Long requestedMoney;
	private Date releaseDate;
	private Date reviewDate;
	private String grantName;
	private String requestDescription;
	private Boolean isOpened;
	private Boolean isDeleted;
	@Mapping("comments")
	private List<CommentEntity> commentEntities = new ArrayList<CommentEntity>(0);
	@Mapping("moneyTransfer")
	private List<MoneyTransferEntity> moneyTransferEntities = new ArrayList<MoneyTransferEntity>(0);
	@Mapping("moneyTransfersFromFund")
	private List<MoneyTransferFromFundEntity> moneyTransferFromFundEntities = new ArrayList<MoneyTransferFromFundEntity>(0);
	private Date creationDate;
	@Mapping("likes")
	private List<LikeEntity> likeEntities = new ArrayList<LikeEntity>(0);
	@Mapping("changelog")
	private List<GrantChangelogEntity> changelog = new ArrayList<GrantChangelogEntity>(0);

	public GrantApplicationEntity() {

	}

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "grantApplicationEntity")
	public List<GrantChangelogEntity> getChangelog() {

		return changelog;
	}

	public void setChangelog(List<GrantChangelogEntity> changelog) {

		this.changelog = changelog;
	}

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "grantApplication")
	public List<MoneyTransferFromFundEntity> getMoneyTransferFromFundEntities() {

		return this.moneyTransferFromFundEntities;
	}

	public void setMoneyTransferFromFundEntities(List<MoneyTransferFromFundEntity> moneyTransferFromFundEntities) {

		this.moneyTransferFromFundEntities = moneyTransferFromFundEntities;
	}

	@Id
	@GeneratedValue(strategy = IDENTITY)

	@Column(name = "grant_id", unique = true, nullable = false, updatable = false)
	public Long getGrantId() {

		return this.grantId;
	}

	public void setGrantId(Long grantId) {

		this.grantId = grantId;
	}

	@ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
	@JoinColumn(name = "grant_area_id", updatable = false)
	public GrantAreaEntity getGrantArea() {

		return this.grantArea;
	}

	public void setGrantArea(GrantAreaEntity grantArea) {

		this.grantArea = grantArea;
	}

	@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
	@JoinColumn(name = "status_id")
	public GrantApplicationStatusEntity getGrantApplicationStatus() {

		return this.grantApplicationStatus;
	}

	public void setGrantApplicationStatus(GrantApplicationStatusEntity grantApplicationStatus) {

		this.grantApplicationStatus = grantApplicationStatus;
	}

	@ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
	@Cascade(org.hibernate.annotations.CascadeType.SAVE_UPDATE)
	@JoinColumn(name = "user_id", updatable = false)
	public UserEntity getUser() {

		return this.user;
	}

	public void setUser(UserEntity user) {

		this.user = user;
	}

	@Column(name = "requested_money", precision = 10, scale = 0)
	@Cascade(org.hibernate.annotations.CascadeType.ALL)
	public Long getRequestedMoney() {

		return this.requestedMoney;
	}

	public void setRequestedMoney(Long requestedMoney) {

		this.requestedMoney = requestedMoney;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "release_date", length = 19, updatable = false)
	public Date getReleaseDate() {

		return this.releaseDate;
	}

	public void setReleaseDate(Date releaseDate) {

		this.releaseDate = releaseDate;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "review_date", length = 19, updatable = true)
	public Date getReviewDate() {

		return this.reviewDate;
	}

	public void setReviewDate(Date reviewDate) {

		this.reviewDate = reviewDate;
	}

	@Column(name = "grant_name", length = 50)
	public String getGrantName() {

		return this.grantName;
	}

	public void setGrantName(String grantName) {

		this.grantName = grantName;
	}

	@Column(name = "request_description", length = 65535)
	public String getRequestDescription() {

		return this.requestDescription;
	}

	public void setRequestDescription(String requestDescription) {

		this.requestDescription = requestDescription;
	}

	@Column(name = "is_opened")
	public Boolean getIsOpened() {

		return this.isOpened;
	}

	public void setIsOpened(Boolean isOpened) {

		this.isOpened = isOpened;
	}

	@Column(name = "is_deleted")
	public Boolean getIsDeleted() {

		return this.isDeleted;
	}

	public void setIsDeleted(Boolean isDeleted) {

		this.isDeleted = isDeleted;
	}

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "grantApplication")
	@org.hibernate.annotations.OrderBy(clause = "comment_date DESC")
	@Fetch(FetchMode.JOIN)
	@Cascade(org.hibernate.annotations.CascadeType.ALL)
	public List<CommentEntity> getComments() {

		return this.commentEntities;
	}

	public void setComments(List<CommentEntity> comments) {

		this.commentEntities = comments;
	}

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "grantApplication")
	@org.hibernate.annotations.OrderBy(clause = "money_sum DESC")
	@Cascade(org.hibernate.annotations.CascadeType.ALL)
	public List<MoneyTransferEntity> getMoneyTransfers() {

		return this.moneyTransferEntities;
	}

	public void setMoneyTransfers(List<MoneyTransferEntity> moneyTransfers) {

		this.moneyTransferEntities = moneyTransfers;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "creation_date", length = 19, updatable = false)
	public Date getCreationDate() {

		return this.creationDate;
	}

	public void setCreationDate(Date creationDate) {

		this.creationDate = creationDate;
	}

	@Override
	public int compareTo(GrantApplicationEntity o) {

		return Integer.compare(this.getLikes().size(), o.getLikes().size());
	}

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "grantApplication")
	public List<LikeEntity> getLikes() {

		return this.likeEntities;
	}

	public void setLikes(List<LikeEntity> likes) {

		this.likeEntities = likes;
	}
}
